package com.example.demo.network;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.jackson.JacksonConverterFactory;

/**
 * @Desc
 * @Author zxp
 * @Date 2024/3/14
 */
public class RetrofitFactory {

    // gitee要把blob改成raw才能访问到原始文件
    private static final String BASE_URL = "https://gitee.com/";

    private static Retrofit retrofit;

    private static Retrofit getRetrofit() {
        if (retrofit == null) {
            synchronized (RetrofitFactory.class) {
                if (retrofit == null) {
                    retrofit = new Retrofit.Builder()
                            .baseUrl(BASE_URL) // 设置 网络请求 Url
                            .addConverterFactory(JacksonConverterFactory.create()) //设置使用jackson解析(记得加入依赖)
                            .addCallAdapterFactory(RxJava3CallAdapterFactory.create()) // 支持RxJava
                            .build();
                }
            }
        }
        return retrofit;
    }

    public static <T> T createService(Class<T> clas) {
        return getRetrofit().create(clas);
    }

}
